package cn.cloud9.designpattern.dp01singleton;

/**
 * @author OnCloud9
 * @description 懒汉式第四种 DoubleCheck
 * @project Java
 * @date 2022年05月22日 10:00
 */
public class Singleton6 {

    private Singleton6 (){}

    // 设置实例可见性？
    private static volatile Singleton6 instance;

    // 二次检查
    public static Singleton6 getInstance(){
        if (instance == null) synchronized (Singleton6.class) {
            if (instance == null) instance = new Singleton6();
        }
        return instance;
    }
}
